var express = require("express"),
	app     = express(),
	server  = require("http").createServer(app),
	io      = require('socket.io').listen(server),
	port    = parseInt(process.env.PORT,10) || 8000;


var http = require('http');

//app.use(express.bodyParser());
app.configure(function(){
	app.use(express.methodOverride());
	app.use(express.bodyParser());
	app.use(express.static(__dirname+'/public/'));
	app.use(express.errorHandler({
		dumpExceptions: true,
		showStack: true
	}));
});

io.set('log level',2);
io.set('transport', ['websocket', 'xhr-polling']);

app.get('/', function(req, res){
  res.redirect("/index.html");
});

var chatters = [];
var roomCounter = 0;
var roomslist = {
	rooms:[{
		name: "FirstRoom",
		id: roomCounter++,
		users: ["dabs","sigga","joi"],
		messages: ["12","12"] }],
};

io.sockets.on('connection', function(socket){

	socket.on('connect',function(data){
		connect(socket,data);
	});

});

function connect(socket,data){

	chatters[socket.id] = data.nick;
	console.log("chatter number "+ socket.id + " nick is: "+chatters[socket.id]);

	socket.emit('roomslist',getRooms());

}

function getRooms(){

}

app.listen(port);
console.log('Chat server is running and listening to port %d...', port);